package com.hby.game

import android.os.Debug
import com.helloandroid.AppUtil
import com.helloandroid.MyApplication
import game.engine.base.*

class ReadyScene : Scene() {


    override fun onTouch(touch: Touch) {
    }

    override fun onEnter() {
        super.onEnter()

        val director = Director.instance
        val graphics = HbyGame.res
        fillBgBitmap = graphics.bgBitmap

        // 标题
        val title = Sprite(bitmap = graphics.titleBitmap)
        title.y = -400f
        addChild(title)

        // info
        val coinInfo = HbConfig.makeCoinInfo()
        addChild(coinInfo)

        val timeInfo = HbConfig.makeTimeInfo()
        addChild(timeInfo)

        val num = Sprite(bitmap = graphics.wordBitmap3)
        num.visible = false
        addChild(num)

        // 开始倒计时
        scheduleOnce(1f){
//            title.removeFromParent()
            num.visible = true
            scheduleCount(1f,3,1f){countIdx->
                when(countIdx){
                    0->num.updateBitmap(graphics.wordBitmap2)
                    1->num.updateBitmap(graphics.wordBitmap1)
                    2->{
                        // 切换到下一个场景
                        UDebug.info("准备切换到下一个场景....")

                        // 上报时间,更新下一次红包雨时间
                        (Director.instance.gameApp as HbyGame).handler.post {
                            AppUtil.appViewModel().hbyReportTimeMs()
                        }

                        director.replaceScene(GameScene())
                    }
                }
            }
        }


        // 显示内存情况
        UDebug.info("getNativeHeapAllocatedSize mem:${Debug.getNativeHeapAllocatedSize()/1024/1024} M")
        UDebug.info("getNativeHeapFreeSize mem:${Debug.getNativeHeapFreeSize()/1024/1024} M")
        UDebug.info("getNativeHeapSize mem:${Debug.getNativeHeapSize()/1024/1024} M")

//        val mem = Runtime.getRuntime().maxMemory() / 1024f / 1024f
//        UDebug.info("maxMemory:${mem} M")
    }
}